import functools
from flask import (
    Blueprint, flash, g, redirect, render_template, request, session, url_for
)
from werkzeug.security import check_password_hash, generate_password_hash
from werkzeug.exceptions import HTTPException

bp = Blueprint('d', __name__, url_prefix='/d')

@bp.post('/json')
def post_json():
    j = request.json
    print(f"j={j}, {type(j)=}")
    return j

@bp.get('/error')
def error():
    a = 1 / 0
    return {
        'msg': 'error'
    }

@bp.errorhandler(Exception)
def handle_exception(e):
    if isinstance(e, HTTPException):
        return e

    return {
        'code': '999',
        'msg': f'{e!r}',
        'type': f'{type(e)}'
    }

